home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_376 / matrix / src / pal / intui.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  13KB  |  470 lines

  1.  /********************************************************************/
  2.  /****                                                            ****/
  3.  /****                                                            ****/
  4.  /****    Program          : Intui.c                              ****/
  5.  /****                                                            ****/
  6.  /****    Version          : 01.00                                ****/
  7.  /****                                                            ****/
  8.  /****    Erstversion      : 01.07.1990                           ****/
  9.  /****                                                            ****/
  10.  /****    Letzte Änderung  : 08.08.1990                           ****/
  11.  /****                                                            ****/
  12.  /****    Compiliert mit   : siehe MAKEFILE                       ****/
  13.  /****                                                            ****/
  14.  /****    Gelinkt mit      : siehe MAKEFILE                       ****/
  15.  /****                                                            ****/
  16.  /********************************************************************/
  17.  /****                                                            ****/
  18.  /****                                                            ****/
  19.  /****               Copyright by Rüdiger Dreier                  ****/
  20.  /****                                                            ****/
  21.  /****                                                            ****/
  22.  /********************************************************************/
  23.  
  24.  /* Einbinden der Include-Files */
  25.  
  26.  
  27.  struct IntuitionBase  *IntuitionBase;  /* Zeiger auf IntuitionBase   */
  28.  struct GfxBase        *GfxBase;        /* Zeiger auf Grafik-Library  */
  29.  struct ToolBase       *ToolBase;
  30.  struct Library        *MathIeeeDoubTransBase;
  31.  struct Library        *MathIeeeDoubBasBase;
  32.  struct Window         *Window;         /* Zeiger auf Fenster         */
  33.  struct RastPort       *RastPort;       /* Zeiger auf RastPort        */
  34.  struct Screen         *Screen;         /* Zeiger auf Screen          */
  35.  struct info           msgInfo;
  36.  struct Menu           *Menu;
  37.  extern struct NewWindow Fenster2;
  38.  
  39.  extern DOUBLE MatrixA[20][20];
  40.  VOID NeueZahl(SHORT AlteZeile,SHORT AlteSpalte);
  41.  VOID Loeschen(VOID);
  42.  
  43.  LONG Breite,Hoehe;
  44.  SHORT AlteZeile=0,NeueZeile,AlteSpalte=0,NeueSpalte;
  45.  char ZahlenWert[20];
  46.  DOUBLE ZahlW;
  47.  
  48.  struct NewScreen Schirm=
  49.   {
  50.    0,0,640,YSCREEN,2,2,1,HIRES,CUSTOMSCREEN,NULL,"Matrix",NULL,NULL
  51.   };
  52.  
  53.  SHORT paare2[]=
  54.   {
  55.    -2,-1,121,-1,121,8,-2,8,-2,-1
  56.   };
  57.  struct Border Rand2=
  58.   {
  59.    0,0,2,3,JAM2,5,(SHORT *)&paare2,NULL
  60.   };
  61.  struct IntuiText RechnenT=
  62.   {
  63.    2,3,JAM2,0,0,NULL,"Gleichung lösen",NULL
  64.   };
  65.  struct StringInfo ZahlenWertS=
  66.   {
  67.    ZahlenWert,NULL,0,19,0,0,5,0,0,0,NULL,0,NULL
  68.   };
  69.  struct Gadget ZahlenWertG=
  70.   {
  71.    NULL,230,LINE3+5,120,10,GADGHCOMP,GADGIMMEDIATE|RELVERIFY,STRGADGET,(APTR)&Rand2,0,NULL,0,(APTR)&ZahlenWertS,2,0 
  72.   };
  73.  struct Gadget RechnenG=
  74.   {
  75.    &ZahlenWertG,500,LINE3+5,120,8,GADGHCOMP,RELVERIFY|GADGIMMEDIATE,BOOLGADGET,(APTR)&Rand2,0,&RechnenT,NULL,NULL,4,0
  76.   };
  77.  
  78.  struct NewWindow Fenster=
  79.   {
  80.    0,10,640,YSCREEN-10,0,1,GADGETUP|MOUSEBUTTONS|MENUPICK,
  81.    BORDERLESS|ACTIVATE,
  82.    &RechnenG,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  83.    CUSTOMSCREEN
  84.   };
  85.  
  86.  VOID _main(VOID)
  87.   {
  88.    if(oeffne())                 /* Öffnen der Libraries, Screen, Fenster      */
  89.     {
  90.      Move(RastPort,0,LINE1);
  91.      Draw(RastPort,640,LINE1);
  92.      
  93.      Move(RastPort,0,LINE2);
  94.      Draw(RastPort,640,LINE2);
  95.      
  96.      Move(RastPort,0,LINE3);
  97.      Draw(RastPort,640,LINE3);
  98.      
  99.      NeueWerte();
  100.      Darstellen(1,0); /* Stelle wird automatisch markiert */
  101.      Eingabebereich();
  102.      
  103.      ActivateGadget(&ZahlenWertG,Window,NULL);
  104.      Events();                  /* Verwertet die Intuition-Messages           */
  105.     }
  106.    ende();                      /* Gibt den belegten Speicher wieder frei     */
  107.   }
  108.  
  109.  /* Öffnet Libraries, Screen, Window */
  110.  SHORT oeffne(VOID)
  111.   {
  112.    SHORT Failed=0;
  113.    if((ToolBase=(struct ToolBase *)OpenLibrary("tool.library",0)))
  114.     {
  115.      IntuitionBase        =ToolBase->IntuitionBase;
  116.      GfxBase              =ToolBase->GfxBase;
  117.      MathIeeeDoubBasBase  =ToolBase->MathIeeeDoubBasBase;
  118.      MathIeeeDoubTransBase=ToolBase->MathIeeeDoubTransBase;
  119.      if((Screen=(struct Screen *)OpenScreen(&Schirm)))
  120.       {
  121.        Fenster.Screen=Screen; /* Fenster soll auf Screen erscheinen */
  122.        if((Window=(struct Window *)OpenWindow(&Fenster)))
  123.         {
  124.          struct MenuItem *item;
  125.          /* Zuweisung von Variablen, Einfärben des Windows */
  126.          RastPort=Window->RPort;            /* Variablenzuweisung          */
  127.          Failed=1;                          /* Nur wenn alles geklappt hat */
  128.          Fenster3.Screen=Fenster2.Screen=Screen;
  129.          Menu=AddMenu(Menu," Gleichungen",MENUENABLED);
  130.          item=AddItem(Menu,"Neue Anzahl",ITEMTEXT|ITEMENABLED|HIGHCOMP,0);
  131.          ((struct IntuiText *)item->ItemFill)->FrontPen=2;
  132.          AddItem(Menu,"Löschen",ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,'C');
  133.          AddItem(Menu,"Lösen",ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,'L');
  134.          AddItem(Menu,"Laden",ITEMTEXT|ITEMENABLED|HIGHCOMP,0);
  135.          AddItem(Menu,"Speichern",ITEMTEXT|ITEMENABLED|HIGHCOMP,0);
  136.          AddItem(Menu,"About",ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,'I');
  137.          AddItem(Menu,"E N D E",ITEMTEXT|ITEMENABLED|HIGHCOMP,0);
  138.          NewSetMenuStrip(Window,Menu);
  139.         }
  140.       }
  141.     }
  142.    return(Failed);
  143.   }
  144.  
  145.  
  146.  /* Routine, die alles wieder schließt */
  147.  VOID ende(VOID)
  148.   {
  149.    LONG H;
  150.    Delay(20);
  151.    
  152.    /* Wenn offen -> schließen */
  153.    if(Window)
  154.     {
  155.      if(Window->MenuStrip)
  156.       {
  157.        ClearMenu(Window->MenuStrip);
  158.        ClearMenuStrip(Window);
  159.       }
  160.      while(H=EventAbfrage(Window,&msgInfo));
  161.      CloseWindow(Window);
  162.     }
  163.    
  164.    if(Screen)CloseScreen(Screen);
  165.    
  166.    if(ToolBase)CloseLibrary((struct Library *)ToolBase);
  167.   }
  168.  
  169.  
  170.  /* Wertet Mausklick aus */
  171.  VOID Events(VOID)
  172.   {
  173.    long item;
  174.    USHORT menunr;
  175.    LONG Mx,My;
  176.    struct MenuItem *Item;
  177.    char ENDE=1;
  178.  
  179.    while(ENDE)
  180.     {
  181.      /* Wartet auf Event */
  182.      Wait(1L<<Window->UserPort->mp_SigBit);
  183.      /* Arbeitet ab, bis keine Events mehr */
  184.      while(EventAbfrage(Window,&msgInfo))
  185.       {
  186.        Mx=msgInfo.MouseX;
  187.        My=msgInfo.MouseY;
  188.        /* Verzweigt entsprechend der Events */
  189.        switch(msgInfo.NachrichtenArt)
  190.         {
  191.          /* Menupunkt gewählt */
  192.          case MENUPICK:
  193.           {
  194.            menunr=msgInfo.code;
  195.            
  196.            /* Wurde wirklich ein Menu gewählt ? */
  197.            while(menunr!=MENUNULL)
  198.             {
  199.              item=ITEMNUM(menunr);
  200.              /* Entsprechend des Menus verzweigen */
  201.              switch (item)
  202.               {
  203.                case 0:
  204.                 {
  205.                  NeueWerte();
  206.                 }
  207.                case 1:
  208.                 {
  209.                  Loeschen();
  210.                  Einsprung_I1:
  211.                  AlteSpalte=AlteZeile=0;
  212.                  Darstellen(1,0); /* Stelle wird automatisch markiert */
  213.                  Eingabebereich();
  214.                  ActivateGadget(&ZahlenWertG,Window,NULL);
  215.                  break;
  216.                 }
  217.                case 2:            
  218.                 {
  219.                  SHORT L;
  220.                  L=Loesen();
  221.                  Darstellen(0,L);
  222.                  ActivateGadget(&ZahlenWertG,Window,NULL);
  223.                  break;
  224.                 }
  225.                case 3:
  226.                 {
  227.                  /* Laden */
  228.                  char Name[50];
  229.                  if(FileRequest(Window,"Laden",160,100,Name))
  230.                   {
  231.                    Werte_Laden(Name);
  232.                   }
  233.                  goto Einsprung_I1;
  234.                 }
  235.                case 4:
  236.                 {
  237.                  /* Speichern */
  238.                  char Name[50];
  239.                  if(FileRequest(Window,"Speichern",160,100,Name))
  240.                   {
  241.                    Werte_Speichern(Name);
  242.                   }
  243.                  goto Einsprung_I1;
  244.                 }
  245.                case 5:
  246.                 {
  247.                  About();
  248.                  break;
  249.                 }
  250.                case 6:
  251.                 {
  252.                  ENDE=0;
  253.                  break;
  254.                 }
  255.               }
  256.              Item=ItemAddress(Menu,(LONG)menunr);
  257.              menunr=Item->NextSelect;
  258.              Item->NextSelect=MENUNULL;
  259.             }
  260.            break;
  261.           }
  262.          case GADGETUP:
  263.           {
  264.            if( (((struct Gadget *)msgInfo.IAddress)->GadgetID) ==4)
  265.             {
  266.              SHORT L;
  267.              L=Loesen();
  268.              Darstellen(0,L);
  269.              ActivateGadget(&ZahlenWertG,Window,NULL);
  270.             }
  271.            else
  272.             {
  273.              UmwStoF(&ZahlW,ZahlenWert);
  274.              MatrixE[AlteZeile][AlteSpalte]=ZahlW;
  275.              
  276.              /* Zahl ausgeben */
  277.              NeueZahl(AlteZeile,AlteSpalte);
  278.              
  279.              AlteSpalte++;
  280.              if(AlteSpalte==Spalten)
  281.               {
  282.                AlteZeile++;
  283.                AlteSpalte=0;
  284.               }
  285.              if(AlteZeile==Zeilen)AlteZeile=0;
  286.              Mark(AlteZeile,AlteSpalte);
  287.              Eingabebereich();
  288.              ActivateGadget(&ZahlenWertG,Window,NULL);
  289.             }
  290.            break;
  291.           }
  292.          case MOUSEBUTTONS:
  293.           {
  294.            if(My<97)
  295.             {
  296.              NeueSpalte=(Mx-12)/Breite;
  297.              NeueZeile =(My-LINE1-1)/Hoehe;
  298.              NeueZeile=min(NeueZeile,Zeilen-1);
  299.              NeueZeile=max(0,NeueZeile); /* Um negative Werte zu verhindern */
  300.              NeueSpalte=min(NeueSpalte,Spalten-1);
  301.              if(NeueSpalte!=AlteSpalte || NeueZeile!=AlteZeile)
  302.               {
  303.                Mark(AlteZeile,AlteSpalte);
  304.                AlteZeile=NeueZeile;
  305.                AlteSpalte=NeueSpalte;
  306.                Mark(AlteZeile,AlteSpalte);
  307.                Eingabebereich();
  308.               }
  309.              ActivateGadget(&ZahlenWertG,Window,NULL);
  310.             }
  311.            break;
  312.           }
  313.         }
  314.       }
  315.     }
  316.   }
  317.  
  318.  
  319.  VOID Mark(SHORT y,SHORT x)
  320.   {
  321.    LONG xp,yp;
  322.    
  323.    xp=x*Breite+ABSTANDL;
  324.    if(AlteSpalte==Spalten-1)
  325.     {
  326.      xp+=ABSTAND;
  327.     }
  328.    yp=y*Hoehe +LINE1+1;
  329.    SetDrMd(RastPort,COMPLEMENT);
  330.    RectFill(RastPort,xp,yp,xp+Breite-1,yp+Hoehe-1);
  331.    SetDrMd(RastPort,JAM1);
  332.   }
  333.  
  334.  VOID NeueZahl(SHORT AlteZeile,SHORT AlteSpalte)
  335.   {
  336.    LONG xp,yp;
  337.    char Zahlen[20];
  338.    /* Mark(AlteZeile,AlteSpalte); */
  339.    
  340.    
  341.    xp=AlteSpalte*Breite+ABSTANDL;
  342.    if(AlteSpalte==Spalten-1)
  343.     {
  344.      xp+=ABSTAND;
  345.     }
  346.    yp=AlteZeile*Hoehe +LINE1+1;
  347.    SetAPen(RastPort,0);
  348.    RectFill(RastPort,xp,yp,xp+Breite-1,yp+Hoehe-1);
  349.    
  350.    UmwFtoS(Zahlen,&MatrixE[AlteZeile][AlteSpalte],3);
  351.    xp=xp+Breite-4-strlen(Zahlen)*8;
  352.    yp=yp+6+(Hoehe-8)/2;
  353.    Print(RastPort,Zahlen,1,xp,yp);
  354.   }
  355.  
  356.  VOID Darstellen(SHORT y,SHORT L)
  357.   {
  358.    char Zahlen[20];
  359.    SHORT i,j;
  360.    LONG xp,yp;
  361.    Mark(AlteZeile,AlteSpalte);
  362.    
  363.    if(y==0)
  364.     {
  365.      SetAPen(RastPort,0);
  366.      RectFill(RastPort,0,LINE2+1,640,LINE3-1);
  367.      SetAPen(RastPort,1);
  368.      Move(RastPort,Breite*(Spalten-1)+15,LINE2+1);
  369.      Draw(RastPort,Breite*(Spalten-1)+15,LINE3-24);
  370.      Center(Window,"L ö s u n g",1,LINE2+12);
  371.      for(i=0;i<Zeilen;i++)
  372.       {
  373.        for(j=0;j<Spalten;j++)
  374.         {
  375.          UmwFtoS(Zahlen,&MatrixA[i][j],3);
  376.          xp=j*Breite+ABSTANDL+Breite-4-strlen(Zahlen)*8;
  377.          if(j==Spalten-1)
  378.           {
  379.            xp+=ABSTAND;
  380.           }
  381.          yp=i*Hoehe +32+LINE2+(Hoehe-8)/2;
  382.          Print(RastPort,Zahlen,1,xp,yp);
  383.         }
  384.       }
  385.      if(L)
  386.       {
  387.        if(L==1)
  388.         {
  389.          Center(Window,"Nicht lösbar !",1,LINE3-6);
  390.         }
  391.        else 
  392.         {
  393.          Center(Window,"Nicht eindeutig lösbar !",1,LINE3-6);
  394.         }
  395.       }
  396.      
  397.     }
  398.    else
  399.     {
  400.      SetAPen(RastPort,0);
  401.      RectFill(RastPort,0,LINE1+1,640,LINE2-1);
  402.      
  403.      SetAPen(RastPort,1);
  404.      Move(RastPort,Breite*(Spalten-1)+15,LINE1+1);
  405.      Draw(RastPort,Breite*(Spalten-1)+15,LINE2-1);
  406.      for(i=0;i<Zeilen;i++)
  407.       {
  408.        for(j=0;j<Spalten;j++)
  409.         {
  410.          UmwFtoS(Zahlen,&MatrixE[i][j],3);
  411.          NeueZahl(i,j);
  412.         }
  413.       }
  414.     }
  415.    Mark(AlteZeile,AlteSpalte);
  416.   }
  417.  
  418.  VOID Eingabebereich(VOID)
  419.   {
  420.    char xs[8],ys[8];
  421.    char Ausgabe[256];
  422.    SetAPen(RastPort,0);
  423.    RectFill(RastPort,154,LINE3+5,229,LINE3+15);
  424.    UmwFtoS(ZahlenWert,&MatrixE[AlteZeile][AlteSpalte],3);
  425.    if(!strcmp(ZahlenWert,"0"))ZahlenWert[0]=0;
  426.    ZahlenWertS.BufferPos=0;
  427.    
  428.    stci_d(xs,AlteSpalte+1);
  429.    stci_d(ys,AlteZeile+1);
  430.    Print(RastPort,"Eingabe für : ",1,50,LINE3+13);
  431.    strcpy(Ausgabe,ys);
  432.    if(AlteZeile<9)
  433.     {
  434.      strcat(Ausgabe," ");
  435.     }
  436.    strcat(Ausgabe,", ");
  437.    strcat(Ausgabe,xs);
  438.    Print(RastPort,Ausgabe,1,155,LINE3+13);
  439.    RefreshGList(&ZahlenWertG,Window,NULL,1);
  440.   }
  441.  
  442.  VOID Loeschen(VOID)
  443.   {
  444.    SHORT i,j;
  445.    SetAPen(RastPort,0);
  446.    RectFill(RastPort,0,LINE2+1,640,LINE3-1);
  447.    SetAPen(RastPort,1);
  448.    Move(RastPort,Breite*(Spalten-1)+15,LINE2+1);
  449.    Draw(RastPort,Breite*(Spalten-1)+15,LINE3-24);
  450.    for(i=0;i<19;i++)
  451.     {
  452.      for(j=0;j<19;j++)
  453.       {
  454.        MatrixE[i][j]=0.0;
  455.       }
  456.     }
  457.   }
  458.  
  459.  
  460.  VOID MemCleanup(VOID)
  461.   {
  462.   }
  463.  
  464.  
  465.  VOID chkabort(VOID)
  466.   {
  467.   }
  468.  
  469.  
  470.